home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
title.cl_
/
title.cl
Wrap
Text File
|
1995-03-12
|
5KB
|
145 lines
Version 1.0 Class
Attribute VB_Name = "clsTitle"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Option Explicit
Private m_Database As String
Private m_Title As String
Private m_ISBN As String
Private m_PublisherID As Long
Private m_PublisherName As String
Private m_Year As Integer
Private m_Description As String
Private m_Notes As String
Private m_Subject As String
Private m_Comments As String
Property Let DatabaseName(theDatabase As String)
m_Database = theDatabase
End Property
Property Let Title(theTitle As String)
m_Title = theTitle
End Property
Property Let ISBN(theISBN As String)
m_ISBN = theISBN
End Property
Property Let PublisherID(thePublisher As Long)
On Error GoTo LetPubIDError
m_PublisherID = thePublisher
ReadPublisherName
Exit Property
LetPubIDError:
If Err.Number = ERR_CANTFINDRECORD Then
LastError = ERR_INVALIDPUBLISHERID
Else
LastError = Err.Number
End If
ErrorHandler vbExclamation
End Property
Property Let PublisherName(theName As String)
' Calling routine must handle errors
ReadPublisherName theName
End Property
Property Let YearPublished(theYear As Integer)
m_Year = theYear
End Property
Property Let Subject(theSubject As String)
m_Subject = theSubject
End Property
Property Let Description(theDescription As String)
m_Description = theDescription
End Property
Property Let Comments(theComments As String)
m_Comments = theComments
End Property
Property Let Notes(theNotes As String)
m_Notes = theNotes
End Property
Property Get DatabaseName() As String
DatabaseName = m_Database
End Property
Property Get Title() As String
Title = m_Title
End Property
Property Get ISBN() As String
ISBN = m_ISBN
End Property
Property Get PublisherID() As Long
PublisherID = m_PublisherID
End Property
Property Get PublisherName() As String
PublisherName = m_PublisherName
End Property
Property Get YearPublished() As Integer
YearPublished = m_Year
End Property
Property Get Subject() As String
Subject = m_Subject
End Property
Property Get Description() As String
Description = m_Description
End Property
Property Get Comments() As String
Comments = m_Comments
End Property
Property Get Notes() As String
Notes = m_Notes
End Property
Private Sub ReadPublisherName(Optional theName As Variant)
' Calling routine must handle errors
Dim db As Database
Dim rs As Recordset
Dim sql As String
If m_PublisherID < 1 Then Err.Raise ERR_OBJECTNOTINITIALIZED
Set db = DBEngine.Workspaces(0).OpenDatabase(m_Database, False, True)
sql = "SELECT [PubID], [Name] FROM Publishers "
If VarType(theName) = vbString Then
sql = sql & " WHERE [Name] = '" & theName & "'"
Else
sql = sql & " WHERE [PubID] = " & m_PublisherID
End If
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
If rs.RecordCount = 0 Then Err.Raise ERR_CANTFINDRECORD
rs.MoveLast
If rs.RecordCount > 1 Then Err.Raise ERR_TOOMANYRECORDS
m_PublisherName = rs![Name]
m_PublisherID = rs![PubID]
End Sub
Public Sub Initialize(rs As Recordset, Optional theDatabaseName As Variant)
Dim db As Database
Dim tbl As Recordset
If Not IsMissing(theDatabaseName) Then m_Database = theDatabaseName
If m_Database = "" Then Err.Raise ERR_DATABASENOTSPECIFIED
m_ISBN = rs![ISBN]
If Not IsNull(rs![Title]) Then m_Title = rs![Title] Else m_Title = ""
If Not IsNull(rs![PubID]) Then m_PublisherID = rs![PubID] Else m_PublisherID = 0
If Not IsNull(rs![Year Published]) Then m_Year = rs![Year Published] Else m_Year = 0
If Not IsNull(rs![Subject]) Then m_Subject = rs![Subject] Else m_Subject = ""
If Not IsNull(rs![Description]) Then m_Description = rs![Description] Else m_Description = ""
If Not IsNull(rs![Notes]) Then m_Notes = rs![Notes] Else m_Notes = ""
If Not IsNull(rs![Comments]) Then m_Comments = rs![Comments] Else m_Comments = ""
If m_PublisherID <> 0 Then
Set db = DBEngine.Workspaces(0).OpenDatabase(m_Database)
Set tbl = db.OpenRecordset("Publishers")
tbl.Index = "PrimaryKey"
tbl.Seek "=", m_PublisherID
If Not rs.NoMatch Then
If Not IsNull(tbl![Name]) Then m_PublisherName = tbl![Name] Else m_PublisherName = ""
Else
m_PublisherName = ""
End If
Else
m_PublisherName = ""
End If
End Sub